<template>
  <div class="login">
    <div class="con">
      <h3 class="center">登录</h3>
      <div class="input">
        <el-input v-model="user.username" clearable></el-input>
      </div>
      <div class="input">
        <el-input v-model="user.password" clearable show-password></el-input>
      </div>
      <div class="center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { reqLogin } from "../../request/api";
import { errorAlert, successAlert } from "../../utils/alert";
export default {
  props: [],
  data() {
    return {
      user: {
        username: "boss",
        password: "123",
      },
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {},
  methods: {
    ...mapActions({
      changeuser: "changeuser",
    }),
    //跳转页面
    login() {
      if (this.user.username == "" || this.user.password == "") {
        errorAlert("账号密码不能为空");
        return;
      }
      reqLogin(this.user).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.changeuser(res.data.list);
          this.$router.push("/home");
        }
      });
    },
  },
};
</script>

<style scoped lang="less">
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(@primary, @primary2);
  position: relative;
}
.con {
  width: 300px;
  padding: 30px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 10px;
}
.center {
  text-align: center;
  margin-bottom: 20px;
}
.input {
  margin-bottom: 20px;
}
</style>